package blue.mqtt4j.internal.client.impl;

import blue.mqtt4j.client.MqttMessage;
import blue.mqtt4j.client.ProducerListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-30
 */
public class LoggerProducerListener implements ProducerListener
{
	private static Logger logger = LoggerFactory.getLogger(LoggerProducerListener.class);

	public LoggerProducerListener()
	{
	}

	@Override
	public void onComplete(MqttMessage message, Throwable cause)
	{
		if (cause == null)
		{
			if (logger.isDebugEnabled())
			{
				logger.debug("Produce successful, topic: {}, QoS: {}", message.topic(), message.qos());
			}
		}
		else
		{
			logger.error("Produce failure, topic: {}, QoS: {}", message.topic(), message.qos(), cause);
		}
	}
}
